package dummy.world

import mars.ns.core._
import mars.io._
import mars.io.formatters._
import mars.ns.visualisation.NetworkVisualizer
import mars.ns.visualisation.PrefuseNetworkVisualizer

object WorldGraph extends Application {

    // example testing some features of the core
    val person: Person = new Person("Sam")
    val person2: Person = new Person("Andy")
    val person3: Person = new Person("Michael")
    val person4: Person = new Person("Roel")
    val person5: Person = new Person("Tinneke")
    person.addDoubleLink(person2, new SchoolMate)
    person.addDoubleLink(person3, new SchoolMate)
    person.addDoubleLink(person4, new SchoolMate)
    person.addDoubleLink(person, new SchoolMate) // now possible to link to yourself, but should only add link once
    person.addDoubleLink(person5, new Family)

    person.addDoubleLink(person5, new Family) // already added, so may not appear in the list
    
    println("-- LINKS EQUAL --")
    val link1 : Link = new Link(person5, new Family)
    println(link1.canEqual(new Link(person5,new Family))) // true
    println(link1.canEqual(new Link(person5,new SchoolMate))) // false
    println(link1.canEqual(new Link(person2,new Family))) // false
    println("-- LINKED OBJECTS --")
    println(person.getLinkedObjects(new SchoolMate)) // Roel, Sam, Michael, Andy
    println(person.getLinkedObjects(new Family)) // Tinneke
    println(person.getLinkedObjects) // Roel, Andy, Michael, Sam, Tinneke
    println(person2.getLinkedObjects) // Sam
    println("-- NETWORK --")
    val network: Network[Node] = new Network()
    network.addNode(person)
    network.addNode(person2)
    network.addNode(person3)
    network.addNode(person4)
    network.addNode(person5)
    println(person.getGroups)
    println("-- LINKED OBJECTS 2 --")
    person.removeDoubleLink(new Link(person, new SchoolMate))
    person.removeDoubleLink(new Link(person4, new SchoolMate))
    println(person.getLinkedObjects(new SchoolMate)) // Andy, Michael
    println("-- GROUPS --")
    person.addDoubleLink(person4, new SchoolMate) // Set Sam <-> Roel back
    println(person.getGroups)
    println(person3.getGroups)
    println("-- COMPONENTS --")
    println(network.getComponents(new SchoolMate)) // (Andy, Sam, Michael,Roel), Tinneke is not a schoolmate
    println(network.getComponents(new Family)) // (Sam and Tinneke), Andy, Roel and Michael are no family
    println(network.getComponents()) // Everyone is connected :o
    person.removeLinksTo(person5)
    person5.removeLinksTo(person)
    println(network.getComponents()) // Tinneke no family anymore
    println("-- VISUALISER --")
    person2.addDoubleLink(person3, new SchoolMate)
    person2.addDoubleLink(person4, new SchoolMate)
    person3.addDoubleLink(person4, new SchoolMate)
    val netvis : NetworkVisualizer[Node] = new PrefuseNetworkVisualizer(network)
    netvis.visualise
    println("-- Serialized Formatter - Format --")
    var sf = new SerializedFormatter[Network[Node]]
    var n = sf.format(network)
    println(n)
    println("-- XML Formatter - FromString --")
    var netw = sf.fromString(n)
    println(netw)
    /*
    println("-- XML Formatter - Format --")
    val f = new NetXMLFormatter()
    val n = f.format(network)
    println(n)
    println("-- XML Formatter - ValidFormat --")  
    println("validFormat = " + f.validFormat(n))
    println("-- XML Formatter - FromString --")  
    val netw = f.fromString(n)
    println(netw)
    println("----")*/
}
